package com.yanqu.road.server.manger.activity.qixi.service;

import com.google.protobuf.InvalidProtocolBufferException;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.activity.QixiProto;
import com.yanqu.road.pb.syncMessage.SyncMessage;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.game.service.IGameServiceCommand;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.sync.message.SyncResponse;

public class QixiGetUserInfoServiceCmd implements IGameServiceCommand {
    @Override
    public SyncResponse execute(SyncMessage.Request request) throws InvalidProtocolBufferException {
        SyncResponse syncResponse = new SyncResponse();
        QixiProto.QixiGetUserInfoReqMsg reqMsg = QixiProto.QixiGetUserInfoReqMsg.parseFrom(request.getDataBytes());

        QixiProto.QixiGetUserInfoRespMsg.Builder resp = QixiProto.QixiGetUserInfoRespMsg.newBuilder();
        resp.setReqProtocolType(reqMsg.getReqProtocolType());
        for (Long userId : reqMsg.getTargetUserIdList()) {
            UserBaseInfo userBaseInfo = UserMgr.getUserBaseInfo(userId, GameServer.getInstance().getServerId());
            if (userBaseInfo == null) {
                continue;
            }
            QixiProto.QixiRelationTemp.Builder temp = QixiProto.QixiRelationTemp.newBuilder();
            temp.setTargetUserId(userId);
            temp.setUserBaseInfo(PlayerBasePb.parsePlayerBaseTempMsg(userBaseInfo));
            temp.setGetFlowerCount(0);
            temp.setSendFlowerCount(0);

            resp.addRelationList(temp);
        }
        syncResponse.setResponseBuilder(resp);
        return syncResponse;
    }
}
